package cn.org.escience.controller;

import cn.org.escience.pojo.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 毕子航 951755883@qq.com
 * @date 2018/06/22
 */
@Api(description = "用户信息存储查询服务")
@RequestMapping(value = "/users")
@RestController
public class UserController {
	public static Map<String, User> USER_MAP;

	@Value("${aa.bb}")
	String value;

	static {
		USER_MAP = new HashMap<>();
		User user1 = User.builder().id("1").username("user1").password("p1").build();
		User user2 = User.builder().id("2").username("user2").password("p2").build();
		User user3 = User.builder().id("3").username("user3").password("p3").build();

		USER_MAP.put("1", user1);
		USER_MAP.put("2", user2);
		USER_MAP.put("3", user3);
	}

	@Value("${discovery.eureka.instance.hostname}")
	String title;

	@ApiOperation("根据用户Id获取用户信息")
	@GetMapping(value = "/{userId}")
	public Object get(@PathVariable("userId") String userId) {
		if (StringUtils.hasText(userId)) {
			User build = User.builder().id(userId).password("password1").username("username1").build();
			return build;
		}
		return null;
	}
}
